<%@page language="java" import="util.*, java.text.*, java.util.Date, java.text.DateFormat, java.math.BigDecimal" %>
<%@ page import="entity.*" %>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- InstanceBegin template="/Templates/two_columns.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>二手易</title>
<!-- InstanceEndEditable -->
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" media="screen" />
<!-- InstanceBeginEditable name="head" -->
<!-- lightbox2 -->
<script type="text/javascript" src="Scripts/prototype.js"></script>
<script type="text/javascript" src="Scripts/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="Scripts/lightbox2.js"></script>
<script src="Scripts/global.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/lightbox2.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/socialWeb.css" type="text/css" media="screen" />
<script type="text/javascript">
<!--
function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   thumb2('image_main', 300);
   }
-->
</script>
<%
            String itemID = request.getParameter("item");
            entity.Book book = null;
            if (itemID != null) {
                book = BookService.incrementClicksAndThenGetById(itemID);
                if (book == null) {
                    response.sendRedirect("IllegalAction.jsp"); //todo:incorrect access or item not found
                    return;
                }
            }
                
            String itemName = "Name";
            Date itemAddDate = new Date();
			DateFormat shortFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 
            int itemCondition = 0;
            int itemQuantity = 0;
            BigDecimal itemPrice = BigDecimal.ZERO;			
            int itemMinRating = 0;
            String itemDescription = "Description";
            String itemLocation = "Location";			
			boolean itemMeet=false;
			boolean itemMail1=false;
			BigDecimal itemPostalFee1 = BigDecimal.ZERO;
			boolean itemMail2=false;
			BigDecimal itemPostalFee2 = BigDecimal.ZERO;
			boolean itemOtherTradingMethod=false;
			String itemOtherTradingMethodDetail="";
			boolean itemCash=false;
			boolean itemEbank=false;
			boolean itemCredit=false;
			boolean itemCheque=false;
			boolean itemPaypal=false;
			boolean itemOtherPayingMethod=false;
			String itemOtherPayingMethodDetail="";			
            int itemClicks = 0;
            int itemStatus = 0;
            String img1 = "default/IMG012.jpg",
                    img2= "default/IMG013.jpg",
                    img3= "default/IMG014.jpg";
			int category = 0;
			String categoryString = "";
            String sellerName = "seller";
			String tag1 = null, tag2 = null, tag3 = null, tag4 = null, tag5 = null;
            String msnID = null;
			
            if (itemID != null) {                
                itemName = book.getName();
                itemAddDate = book.getAddDate();
                itemCondition = book.getCondition();
                itemQuantity = book.getQuantity();
                itemPrice = book.getPrice().setScale(2);
                itemMinRating = book.getMinRating();
                itemDescription = book.getDescription();
                itemLocation = book.getLocation();
				itemMeet = book.getMeet();
				itemMail1 = book.getMail1();
				itemPostalFee1 = book.getPostalFee1().setScale(2);	
				itemMail2 = book.getMail2();
				itemPostalFee2 = book.getPostalFee2().setScale(2);
				itemOtherTradingMethod = book.getOtherTradingMethod();
				itemOtherTradingMethodDetail = book.getOtherTradingMethodDetail();
				itemCash = book.getCash();
				itemEbank = book.getEbank();
				itemCredit = book.getCredit();
				itemCheque = book.getCheque();
				itemPaypal = book.getPaypal();
				itemOtherPayingMethod = book.getOtherPayingMethod();
				itemOtherPayingMethodDetail = book.getOtherPayingMethodDetail();
                itemClicks = book.getClicks();
                itemStatus = book.getStatusCode();
                img1 = book.getImage1();
                img2 = book.getImage2();
                img3 = book.getImage3();
                img1 = img1 == null?"default/no_photo.jpg":img1;
				category = book.getCategory();
				
				sellerName = book.getPerson().getLoginname();
                msnID = book.getPerson().getMsn();

				tag1 = book.getTag1();
				tag2 = book.getTag2();
				tag3 = book.getTag3();
				tag4 = book.getTag4();
				tag5 = book.getTag5();
            }
            String site_url = request.getRequestURL().append("?").append(request.getQueryString()).toString();
			String site_title = "二手易: " + itemName;
%>
<!-- InstanceEndEditable -->
</head>
<body>
<div class="main">
  <div class="header">
    <div class="header-top">
      <div class="login-bg"><a href="login.jsp" class="black-link">登入</a><span class="style3"> |</span><a href="#" class="black-link">買賣須知</a><span class="style3"> |</span><a href="#" class="black-link">聯絡我們</a><span class="style3">|</span><a href="#" class="black-link">關於2HE</a></div>
    </div>
    <div class="header-bottom"><!-- InstanceBeginEditable name="NavBar" -->
      <div id="navcontainer">
        <ul class="navlist">
          <li class=""><a href="index.jsp">首頁</a></li>
          <li class=""><a href="#">要買</a></li>
          <li class=""><a href="AddItem.jsp">要賣</a></li>
          <li class=""><a href="changeInfo.jsp">我的主頁</a></li>
          <li class=""><a href="#">我的信箱</a></li>
        </ul>
      </div>
      <!-- InstanceEndEditable --></div>
  </div>
  <div class="body-main">
    <div class="body-leftbar-2column"><!-- InstanceBeginEditable name="leftcolumn" -->
      <div class="left-boxbar-2column-outer">
        <div class="left-boxbar-2column">
          <div class="title-back">
            <div class="item-picture-box">
              <div class="picture-border">
                <table bordercolor="#000000">
                  <tbody>
                    <tr>
                      <td width="310px" height="330px" rowspan="3" align="center" class="picture-cell"><p><img src="items/<%=img1%>" name="image_main" id="image_main"  width="300" height="300" onLoad="thumb2('image_main', 300)" /></p></td>
                      <td align="left"><a href="items/<%=img1%>" onmouseover="roll('image_main', 'items/<%=img1%>')" rel="lightbox[a]"><img src="items/<%=img1%>" name="image1" id="image1" border="0px" width="120"  onLoad="thumb2('image1', 120)"/></a></td>
                    </tr>
                    <tr>
                      <td align="left"><% if(img2 != null) {%>
                        <a href="items/<%=img2%>" onmouseover="roll('image_main', 'items/<%=img2%>')" rel="lightbox[a]"><img src="items/<%=img2%>" name="image2" id="image2" border="0px" width="120" onLoad="thumb2('image2', 120)" /></a>
                        <% }%></td>
                    </tr>
                    <tr>
                      <td align="left"><% if(img3 != null) {%>
                        <a href="items/<%=img3%>" onmouseover="roll('image_main', 'items/<%=img3%>')" rel="lightbox[a]"><img src="items/<%=img3%>" name="image3" id="image3" border="0px" width="120" onLoad="thumb2('image3', 120)" /></a>
                        <%}%></td>
                    </tr>
                    <tr>
                      <td align="center"><% if(img1 !=null){%>
                        圖片預覽
                        <%}else{%>
                        此物品沒有圖片預覽
                        <%}%></td>
                      <td align="center"><% if(img1 !=null){%>
                        按圖檢視原本尺寸
                        <%}%></td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div class="title-back">
            <div class="item-detail-box"><br/>
              <table>
                <tbody align="left" valign="top">
                	<tr>
                    <td> 物品名稱:</td>
                    <td><b><font color="#FF0000"><%=itemName%></font></b></td>
                  </tr>
                  <tr>
                    <td width="130"> 物品類別:</td>
                    <td width="376"><a href="search.jsp?cat=<%=category%>"><%=util.Constant.category(category)%></a></td>
                  </tr>
                  
                  <tr>
                    <td>賣家資料(信用評級):</td>
                    <td><a href='UserProfile.jsp?user=<%=sellerName%>'><%=sellerName%></a>(??)</td>
                  </tr>
                  
                   <tr>
                    <td>MSN狀態:</td>
                    <td><%if(msnID != null) {%>
                        <iframe src="msn.jsp?msn=<%=msnID%>" style="0px; width: 25px; height: 25px;" frameborder="0" scrolling="no" marginheight="5" marginwidth="0" ></iframe>
                        (如果賣家在線,可以按icon直接對話)
                        <%}else{%>
                        沒有登記MSN
                        <%}%>
                    </td>
                  </tr>
                  
                  <tr>
                    <td>上載時間:</td>
                    <td><%=shortFormat.format(itemAddDate)%></td>
                  </tr>
                  <tr>
                    <td> 新淨度:</td>
                    <td>
                    <%if (itemCondition==0){%>
					全新		
                    <%}else if (itemCondition==7){%>
					使用不到一週
                    <%}else if (itemCondition==30){%>
					使用不滿一個月
                    <%}else if (itemCondition==90){%>
					使用一到三個月
                    <%}else if (itemCondition==182){%>
					使用未滿半年
                    <%}else if (itemCondition==365){%>
					使用未滿一年
                    <%}else if (itemCondition==670){%>
					使用一到二年
                    <%}else if (itemCondition==1035){%>
					使用二到三年
                    <%}else if (itemCondition==99999){%>
					使用三年以上
                    <%}%>
                    </td>
                  </tr>
                  <tr>
                    <td> 數量:</td>
                    <td><%=itemQuantity%></td>
                  </tr>
                  <tr>
                    <td> 價錢:</td>
                    <td><b><font color="#FF0000">HK$<%=itemPrice%></font></b></td>
                  </tr>
                  <tr>
                    <td> 購買所需評級:</td>
                    <td><%if (itemMinRating==-999999){%>
                    	不需要
                        <%}else{%>
                        <%=itemMinRating%>
                        <%}%>
                    </td>
                  </tr>
                  <tr>
                    <td>點擊次數:</td>
                    <td><%=itemClicks%></td>
                  </tr>
                  <tr>
                    <td>買賣狀態:</td>
                    <td>					
                    <%if (itemStatus==0){%>
					可以購買		
                    <%}else if (itemStatus==1){%>
					售賣已結束
                    <%}%>
                    </td>
                  </tr>
                  <tr>
                    <td>關鍵字:</td>
                    <td><%if(tag1 != null) {%>
                      <a href="search.jsp?tag=<%=tag1%>"><%=tag1%></a>
                      <%} if(tag2 != null) {%>
                      ,<a href="search.jsp?tag=<%=tag2%>"><%=tag2%></a>
                      <%} if(tag3 != null) {%>
                      ,<a href="search.jsp?tag=<%=tag3%>"><%=tag3%></a>
                      <%} if(tag4 != null) {%>
                      ,<a href="search.jsp?tag=<%=tag4%>"><%=tag4%></a>
                      <%} if(tag5 != null) {%>
                      ,<a href="search.jsp?tag=<%=tag5%>"><%=tag5%></a>
                      <%}%></td>
                  </tr>  
                  <tr>
                    <td valign="top" class="table-separator">分享:</td>
                    <td align="left" class="table-separator"><div id="socialWeb">
                        <ul>
                          <li><a id="ic_google_bmarks" title="Google " target="_blank" rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=<%=site_url%>"><span>Google </span></a></li>
                          <li><a id="ic_facebook" title="Facebook" target="_blank" rel="nofollow" href="http://www.facebook.com/share.php?u=<%=site_url%>"><span>Facebook</span></a></li>
                          <li><a id="ic_delicious" title="Delicious" target="_blank" rel="nofollow" href="http://del.icio.us/post?url=<%=site_url%>&title=<%=site_title%>"><span>Delicious</span></a></li>
                          <li><a id="ic_stumbleupon" title="Stumble Upon" target="_blank" rel="nofollow" href="http://www.stumbleupon.com/submit?url=<%=site_url%>&title=<%=site_title%>"><span>Stumble Upon</span></a></li>
                          <li><a id="ic_magnolia" title="Ma.gnolia" target="_blank" rel="nofollow" href="http://ma.gnolia.com/bookmarklet/add?url=<%=site_url%>&title=<%=site_title%>"><span>Ma.gnolia</span></a></li>
                          <li><a id="ic_windows_live" title="LIVE (MSN)" target="_blank" rel="nofollow" href="https://favorites.live.com/quickadd.aspx?marklet=1&mkt=utf-8&url=<%=site_url%>"><span>LIVE (MSN)</span></a></li>
                          <li><a id="ic_reddit" title="Reddit" target="_blank" rel="nofollow" href="http://reddit.com/submit?url=<%=site_url%>&title=<%=site_title%>"><span>Reddit</span></a></li>
                        </ul>
                        <br/>
                      </div></td>
                  </tr>  
                  <tr>
                    <td class="table-separator">交易方式</td>
                    <td class="table-separator">
                    <ul>
					<%if(itemMeet==true){%>
                    <li>見面交收: <%=itemLocation%></li>
                    <%}%>
					<%if(itemMail1==true){%>
                    <li>郵寄平郵 - 賣家應繳郵費:<b><font color="#FF0000">HK$<%=itemPostalFee1%></font></b></li>
                    <%}%>
                    <%if(itemMail2==true){%>
                    <li>郵寄掛號 - 賣家應繳郵費:<b><font color="#FF0000">HK$<%=itemPostalFee2%></font></b></li>
                    <%}%>
                    <%if(itemOtherTradingMethod==true){%>
                    <li>其他:<%=itemOtherTradingMethodDetail%></li>
                    <%}%>
                    </ul>
                    </td>
                  </tr>
                  <tr>
                    <td>付款方法</td>
                    <td>
                    <ul>
					<%if(itemCash==true){%>
                    <li>接受現金</li>
                    <%}%>
					<%if(itemEbank==true){%>
                    <li>銀行轉帳</li>
                    <%}%>
                    <%if(itemCredit==true){%>
                    <li>接受信用卡</li>
                    <%}%>
                    <%if(itemCheque==true){%>
                    <li>現金支票或匯票</li>
                    <%}%>
                    <%if(itemPaypal==true){%>
                    <li>PayPal</li>
                    <%}%>
                    <%if(itemOtherPayingMethod==true){%>
                    <li>其他:<%=itemOtherPayingMethodDetail%></li>
                    <%}%>
                    </ul>
                    </td>
                  </tr>                                
                                  
                </tbody>
              </table>
              <table width="510" border="0" cellspacing="5" cellpadding="5">
                <tr>
                  <td scope="row" width="168"><img src="images/button_complaint.gif" width="160" height="50" /></td>
                  <td  width="100">&nbsp;</td>
                  <td  width="168"><img src="images/button_buy.gif" width="160" height="50" /></td>
                </tr>
              </table>
            </div>
          </div>
          <div class="title-back">
            <div class="item-description-box">
              <p>
                <%if ((itemDescription==null) || (itemDescription=="")){%>
                此物品沒有介紹。
                <%}else{%>
                <%=itemDescription%>
                <%}%>
              </p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
            </div>
          </div>
          <div class="title-back">
            <div class="item-comment-box">
              <p>Comment </p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
            </div>
          </div>
        </div>
      </div>
      <!-- InstanceEndEditable --></div>
    <div class="body-rightbar-2column">
      <div class="right-boxbar-2column"><!-- InstanceBeginEditable name="rightcolumn" -->
        <div class="title-back">
          <div class="item-related-box">
          <table width="300" border="0" cellspacing="5" cellpadding="5">
          <% if(book != null) {
				if(book.getPerson() != null) {
					categoryString = Integer.toString(category);
					java.util.List<Book> categoryBooks = BookService.getByCategory(categoryString);
				
				for(int i=0; i<5&&i<categoryBooks.size(); i++) {
					Book categoryBook = categoryBooks.get(i);
			%>
           
              <tr>
                <td class="picture-cell">
                <a href="ItemDetail.jsp?item=<%=categoryBook.getBookID()%>">
                    <%if(categoryBook.getImage1() != null) {%>
                        <img id="category_image<%=i%>" name="category_image<%=i%>" src="items/<%=categoryBook.getImage1()%>" width="120" height="120" border="0" onLoad="thumb2('category_image<%=i%>', 120)"/>
                    <%}else{%>
                        <img src="items/default/no_photo_small.jpg" width="120" height="120" border="0"/>
                    <%}%>
                    </a>
                </td>
                <td align="left"><p>物品:<a href="ItemDetail.jsp?item=<%=categoryBook.getBookID()%>"><%=categoryBook.getName()%></a><br />
                    賣家:<%=categoryBook.getPerson().getLoginname()%><br />
                    價錢:<%=categoryBook.getPrice()%></td>
             </tr>
             <%}}}%>
            </table>
          </div>
        </div>
        <div class="title-back">
          <div class="item-other-box">
            <table width="300" border="0" cellspacing="10" cellpadding="0">
            <% if(book != null) {
				if(book.getPerson() != null) {
					java.util.List<Book> relatedBooks = book.getPerson().getBooks();
				
				for(int i=0; i<5&&i<relatedBooks.size(); i++) {
					Book relatedBook = relatedBooks.get(i);
			%>
              <tr>
                <td class="picture-cell">
                    <a href="ItemDetail.jsp?item=<%=relatedBook.getBookID()%>">
                    <%if(relatedBook.getImage1() != null) {%>
                        <img id="other_image<%=i%>" name="other_image<%=i%>" src="items/<%=relatedBook.getImage1()%>" width="120" height="120" border="0" onLoad="thumb2('other_image<%=i%>', 120)"/>
                    <%}else{%>
                        <img src="items/default/no_photo_small.jpg" width="120" height="120" border="0"/>
                    <%}%>
                    </a>
                </td>
                <td align="left">物品:<a href="ItemDetail.jsp?item=<%=relatedBook.getBookID()%>"><%=relatedBook.getName()%></a><br/>
                    價錢:<%=relatedBook.getPrice()%></td>
              </tr>             
             <%}}}%>
              
            </table>
          </div>
        </div>
        <!-- InstanceEndEditable --></div>
    </div>
  </div>
  <div class="footer">Copyright&copy; <a href="http://www.2handeasy.com" class="footer-link">二手易</a> All rights reserved.  |  版權所有不得轉載</div>
</div>
</body>
<!-- InstanceEnd -->
</html>
